
--DELETE FROM CAT_PICTURE
INSERT INTO cat_picture
SELECT 
case len(convert(varchar(10),id))
	when 6 then '00000000-0000-0000-0000-000000' + convert(varchar(10),id) 
    when 5 then '00000000-0000-0000-0000-0000000' + convert(varchar(10),id) 
    when 4 then '00000000-0000-0000-0000-00000000' + convert(varchar(10),id) 
    when 3 then '00000000-0000-0000-0000-000000000' + convert(varchar(10),id) 
    when 2 then '00000000-0000-0000-0000-0000000000' + convert(varchar(10),id) 
    when 1 then '00000000-0000-0000-0000-00000000000'+ convert(varchar(10),id) 
    end As Id,case len(convert(varchar(10),companyid))
    when 5 then '00000000-0000-0000-0000-0000000' + convert(varchar(10),companyid) 
    when 4 then '00000000-0000-0000-0000-00000000' + convert(varchar(10),companyid) 
    when 3 then '00000000-0000-0000-0000-000000000' + convert(varchar(10),companyid) 
    when 2 then '00000000-0000-0000-0000-0000000000' + convert(varchar(10),companyid) 
    when 1 then '00000000-0000-0000-0000-00000000000'+ convert(varchar(10),companyid) 
    end AS [CompanyId],PhotoDes AS [Title],photo AS [PictureBinary],NULL AS [ImageUrl],NULL AS [MimeType],NULL AS [Width],NULL AS [Height],NULL AS [Size],NULL AS [SortOrder],0 AS [IsLogo]FROM srv_lnk.nchr2008.dbo.CompanyPhoto
where NOT PHOTO IS NULL AND companyid in(select id from companyinfo)

